package com.vterm4aKafka.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vterm4aKafka.domain.DeptInfo;
import com.vterm4aKafka.domain.FourAInfo;
import com.vterm4aKafka.domain.FourAInfoReq;
import com.vterm4aKafka.mapper.FourAInfoSearchMapper;
import com.vterm4aKafka.service.FourAInfoSearchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ program: elasticSearch_springBoot_study
 * @ description:
 * @ author: Mr.Zhongsf
 * @ create: 2021-03-18 09:56
 **/
@Service("FourAInfoSearchService")
public class FourAInfoSearchImpl implements FourAInfoSearchService {
    @Resource
    FourAInfoSearchMapper fourAInfoSearchMapper;
    @Override
    public PageInfo<FourAInfo> selectFourAInfo(FourAInfoReq fourAInfoReq) {


        List<DeptInfo> deptInfos = fourAInfoSearchMapper.selectOrgInfo(fourAInfoReq);
        String deptName = deptInfos.get(0).getDeptName();
        fourAInfoReq.setDeptName(deptName);

        // 开启分页插件,放在查询语句上面 帮助生成分页语句
        PageHelper.startPage(fourAInfoReq.getPage(), fourAInfoReq.getPageSize());

        //若不使用pagehelper 则这么计算offset
        //fourAInfoReq.setPage((vtermDefaultInfoRe.getPage()-1)* (vtermDefaultInfoRe.getPageSize()));

        List<FourAInfo> fourAInfos = fourAInfoSearchMapper.selectFourAInfo(fourAInfoReq);

        for (FourAInfo fourAInfo : fourAInfos) {
            if (fourAInfo.getBeginTime().length()+fourAInfo.getBeginTime().length()+fourAInfo.getBeginTime().length()>54){
                fourAInfo.setBeginTime(fourAInfo.getBeginTime().substring(0,19));
                fourAInfo.setEndTime(fourAInfo.getEndTime().substring(0,19));
                fourAInfo.setOperTime(fourAInfo.getOperTime().substring(0,19));
            }
        }
        PageInfo<FourAInfo> pageInfos = new PageInfo<>(fourAInfos);

        return pageInfos;
    }


}

